package  
{
	import flash.display.ColorCorrection;
	import flash.display.Shape;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	import org.flixel.FlxSprite;
	import org.flixel.FlxG;
	/**
	 * ...
	 * @author morgan
	 */
	public class Sun extends FlxSprite
	{
		public var sx:int;
		public var sy:int;
		
		public var beams:int = 13;
		public var space:Number = 0.5;
		public var time:Number = 0;
		
		public function Sun(sx:int, sy:int) 
		{
			super(0, 0, null);
			this.sx = sx;
			this.sy = sy;
			makeGraphic(320, 240, 0x00000000);
		}
		
		override public function update():void 
		{
			super.update();
			time += FlxG.elapsed;
			if (GameState.ref.mode == 0) 
			{
				sx = GameState.FIELDLEFT - 50; sy = -50;
				color = 0xfff600;
			}
			else if (GameState.ref.mode == 1)
			{
				sx = GameState.FIELDLEFT + GameState.FIELDWIDTH / 2; sy = -40;
				color = 0xff0000;				
			}
			else
			{
				sx = GameState.FIELDLEFT + GameState.FIELDWIDTH + 50; sy = -50;
				color = 0xffffff;	
			}
		}
		
		override public function draw():void 
		{
			var s:Shape = new Shape;

			for (var i:int = 0; i < beams; i++)
			{
				color = 0xffffff;
				var base:Number = i * Math.PI * 2 / beams + time / 8;
				var a1:Number = base + (Math.PI * 2 / beams) * space / 2;
				var a2:Number = base + (Math.PI * 2 / beams) * (1 - space / 2);
				s.graphics.beginFill(color, 0.1);
				s.graphics.moveTo(sx, sy);
				s.graphics.lineTo(sx + Math.cos(a1) * 400, sy + Math.sin(a1) * 400);
				s.graphics.lineTo(sx + Math.cos(a2) * 400, sy + Math.sin(a2) * 400);
				s.graphics.lineTo(sx, sy);
				s.graphics.endFill();
			}
			FlxG.camera.buffer.draw(s);
		}
		
	}

}